<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Date		2011-08
 * By		o熊小猫o
 * Email	show1990@foxmail.com
 *
 */
class Home extends CI_Controller {

	public function __construct() {
		parent::__construct();
		//后台全局验证登陆超时
		$u		=	$this->session->userdata('admin');
		$name	=	$this->session->userdata('name');
		if ( ! $u == 'ok')
		{
			$this->session->sess_destroy();
			redirect(site_url('admin/login'));
		}
		//类库
		$this->load->library('pagination','email');//分页类
	}

	//退出登录
	function outlog()
	{
		$this->session->sess_destroy();
		redirect(site_url('admin/login'));
	}
	//退出登录 End


	//后台首页
	function index()
	{
		$admin	=	$this->config->item('admin');
		$data['style']=$this->config->item('style');
		$this->load->view("$admin/home",$data);
	}
	//后台首页 End
	
	/**
	 * news新闻
	 *
	 */
	
	function news_list()
	{
		$arr			=		array(
		'id >'	=>		0,
		);
		$config['base_url'] = site_url().'admin/home/news_list';
		$config['total_rows'] = $this->model->select_num_rows('news',$arr);
		$config['per_page'] = '2';
		$config['num_links'] = 3;
		$config['uri_segment'] = 4;
		$config['first_link'] = '&laquo;首页';
		$config['prev_link'] = '&laquo;上一页';
		$config['next_link'] = '下一页 &raquo;';
		$config['last_link'] = '尾页 &raquo;';
		//$config['anchor_class'] = 'number'; 
		$this->pagination->initialize($config);//初始化分页类
		$data['show']	=	$this->model->get_page('news',$config['per_page'],$this->uri->segment(4,0),'desc',$arr);//主列表
		$this->load->view('admin/news/list',$data);
	}

	function news_update()
	{
		$arr		=		array(
		'id'		=>		$this->uri->segment(4),
		);
		$data['show']	=	$this->model->news('news','category',$arr);
		$data['show1']	=	$this->model->get('category');
		$this->load->view("admin/news/update",$data);
	}
	
	function news_update_go()
	{
		if ($this->input->post('submit'))
		{
			$data			=		array(
			'title'			=>		$this->input->post('title'),
			'keyword'		=>		$this->input->post('keyword'),
			'source'		=>		$this->input->post('source'),
			'author'		=>		$this->input->post('author'),
			'content'		=>		$this->input->post('content'),
			);
			$query	=	$this->model->update('news',$data,$this->uri->segment(4));
			if ($query>0){
				redirect(site_url('admin/home/news_list'));//成功
			}else {
				echo "更新失败，影响条数据".$query;
			}
		}else {
			echo "请勿非法提交";
		}
	}

	function news_delete_go()
	{
		$query	=	$this->model->delete('news',$this->uri->segment(4));
		if ($query>0){
			redirect(site_url('admin/home/list'));//成功
		}else {
			echo "更新失败，影响条数据".$query;
		}
	}

	function news_insert()
	{
		$this->load->view("admin/news/insert");
	}

	function news_insert_go()
	{
		if ($this->input->post('submit'))
		{
			$data			=		array(
			'title'			=>		$this->input->post('title'),
			'keyword'		=>		$this->input->post('keyword'),
			'source'		=>		$this->input->post('source'),
			'author'		=>		$this->input->post('author'),
			'content'		=>		$this->input->post('content'),
			'date'			=>		time(),
			);
			$query	=	$this->model->insert('news',$data);
			if ($query>0){
				redirect(site_url('admin/home/news_list'));//成功
			}else {
				echo "更新失败，影响条数据".$query;
			}
		}else {
			echo "请勿非法提交";
		}
	}

	/**
	* 软件操作
	*
	*/
	
	function software_insert()
	{
		$data['category']	=	$this->model->get('category','asc');
		$this->load->view("admin/software/insert",$data);
	}
	
	function pull()
	{
		$this->load->view("admin/software/pull");
	}
	
	function pull_go()
	{

		if ($this->input->post('submit'))
		{
			$url	=	 $this->input->post('url');
			//die();
			 $apiUrl="$url";
			 $curlObj = curl_init();
			 curl_setopt($curlObj, CURLOPT_URL, $apiUrl);
			 curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
			 curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
			 curl_setopt($curlObj, CURLOPT_HEADER, 0);
			 curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
			 $response = curl_exec($curlObj);
			 curl_close($curlObj);
			 $json = json_decode($response);
			 print_r($json);
/*			 $data['title']	=	$json->FileName;
			 $data['developer']		=	$json->FileName;
			 $data['uptime']		=	$json->FileName;
			 $data['system']		=	$json->FileName;
			 $data['version']		=	$json->FileName;
			 $data['language']		=	$json->FileName;
			 $data['app']			=	$json->FileName;
			 $data['img1']			=	$json->FileName;
			 $data['img2']			=	$json->FileName;*/
			 //$this->load->view("admin/software/pull_go");

/*			if ($query) {
				$this->load->view("admin/software/list",$data);//成功
			}else {
				echo '提取数据出错';
			}*/
		}else {
			echo '请勿非法提交数据';
		}

	}
		
	function software_insert_go()
	{
		if ($this->input->post('submit'))
		{
			$data	=	array(
			'title'			=>		$this->input->post('title'),				//软件标题
			'developer'		=>		$this->input->post('developer'),			//开发者
			'category_id'	=>		$this->input->post('category_id'),			//对应栏目id
			'uptime'		=>		$this->input->post('uptime'),				//官方更新时间
			'system'		=>		$this->input->post('system'),				//系统要求
			'version'		=>		$this->input->post('version'),				//当前软件版本
			'language'		=>		$this->input->post('language'),				//语言
			'app'			=>		$this->input->post('app'),					//适用设备(iphone、ipad通用)
			'date'			=>		time(),										//当前时间(本站发布时间)
			'url_115'		=>		$this->input->post('url_115'),				//官方地址
			'img1'			=>		$this->input->post('img1'),					//75*75图标
			'img2'			=>		$this->input->post('img2'),					//100*100图标
			'img3'			=>		$this->input->post('img3'),					//175*175图标
			'cracked'		=>		$this->input->post('cracked'),				//是否提供破解(1是0否)
			'url'			=>		$this->input->post('url'),					//itunes地址
			'recommend'		=>		$this->input->post('recommend'),			//是否推荐(1是0否)
			'photo'			=>		$this->input->post('photo'),				//多图幻灯片
			'features'		=>		$this->input->post('features'),				//新版功能
			'content'		=>		$this->input->post('content'),				//内容提要
			'down'			=>		$this->input->post('down'),					//下载次数
			//'recycle'		=>		1,											//软件状态(1正常0回收站)
			);

			$query	=	$this->model->insert('soft',$data);
			if ($query) {
				redirect(site_url('admin/home/software_list'));//成功
			}else {
				echo '添加数据出错';
			}
		}else {
			echo '请勿非法提交数据';
		}

	}

	function software_list()
	{
		$arr			=		array(
		'id >'	=>		0,
		);
		$config['base_url'] = site_url().'admin/home/software_list';
		$config['total_rows'] = $this->model->select_num_rows('soft',$arr);
		$config['per_page'] = '1';
		$config['num_links'] = 3;
		$config['uri_segment'] = 4;
		$config['first_link'] = '&laquo;首页';
		$config['prev_link'] = '&laquo;上一页';
		$config['next_link'] = '下一页 &raquo;';
		$config['last_link'] = '尾页 &raquo;';
		//$config['anchor_class'] = 'number'; 
		$this->pagination->initialize($config);//初始化分页类
		$data['show']	=	$this->model->get_page('soft',$config['per_page'],$this->uri->segment(4,0),'desc',$arr);//主列表
		$this->load->view("admin/software/list",$data);
	}

	function software_update()
	{
		$data		=		array(
		'id'		=>		$this->uri->segment(4),
		);
		$data['show']	=	$this->model->select('soft',$data,'desc');//表名,data,排序
		$this->load->view("admin/software/update",$data);
	}

	function software_update_go()
	{
		if ($this->input->post('submit'))
		{
			$data	=	array(
			'title'			=>		$this->input->post('title'),				//软件标题
			'developer'		=>		$this->input->post('developer'),			//开发者
			'category_id'	=>		$this->input->post('category_id'),			//对应栏目id
			'uptime'		=>		$this->input->post('uptime'),				//官方更新时间
			'system'		=>		$this->input->post('system'),				//系统要求
			'version'		=>		$this->input->post('version'),				//当前软件版本
			'language'		=>		$this->input->post('language'),				//语言
			'app'			=>		$this->input->post('app'),					//适用设备(iphone、ipad通用)
			'url_115'		=>		$this->input->post('url_115'),				//官方地址
			'img1'			=>		$this->input->post('img1'),					//75*75图标
			'img2'			=>		$this->input->post('img2'),					//100*100图标
			'img3'			=>		$this->input->post('img3'),					//175*175图标
			'cracked'		=>		$this->input->post('cracked'),				//是否提供破解(1是0否)
			'url'			=>		$this->input->post('url'),					//itunes地址
			'recommend'		=>		$this->input->post('recommend'),			//是否推荐(1是0否)
			'photo'			=>		$this->input->post('photo'),				//多图幻灯片
			'features'		=>		$this->input->post('features'),				//新版功能
			'content'		=>		$this->input->post('content'),				//内容提要
			'down'			=>		$this->input->post('down'),					//下载次数
			//'recycle'		=>		1,											//软件状态(1正常0回收站)
			);

			$query	=	$this->model->update('soft',$data,$this->uri->segment(4));//表,data,ID
			if ($query) {
				redirect(site_url('admin/home/software_list'));//成功
			}else {
				echo '更新数据出错';
			}
		}else {
			echo '请勿非法提交数据';
		}
	}

	function software_delete_go()
	{
		$id		=	$this->uri->segment(4);
		$query	=	$this->model->delete('soft',$id);
		if ($query)
		{
			redirect(site_url('admin/home/software_list'));//ok
		}else {
			echo '删除数据出错';
		}
	}


	/**
	 * messages
	 * 消息
	 *
	 */
	
	function messages_list()
	{
		$data		=		array(
		'recycle'	=>		1,
		);
		$data['messages_list']	=	$this->model->get('messages','desc');//表名,data,排序
		$this->load->view("admin/software/software_list",$data);
	}
	
	/**
	 * analysis
	 * 115解析程序参数设置
	 */
	
	function analysis()
	{
		$data		=		array(
		'id'	=>		1,
		);
		$data['show']	=	$this->model->get('analysis','desc');//表名,data,排序
		$this->load->view("admin/analysis/update",$data);
	}
	
	function analysis_update_go()
	{
		if ($this->input->post('submit'))
		{
			$data	=	array(
			'host'			=>		$this->input->post('host'),				//目标主机
			'version'		=>		$this->input->post('version'),			//
			'date'			=>		time(),									//本次更新时间
			);

			$query	=	$this->model->update('analysis',$data,$this->uri->segment(4));//表,data,ID
			if ($query) {
				redirect(site_url('admin/home/analysis'));//成功
			}else {
				echo '更新数据出错';
			}
		}else {
			echo '请勿非法提交数据';
		}
	}
	
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */